package com.topInterview;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: huangzhigao
 * @Date: 2022/2/20 17:38
 */
public class Leecode78_subSet {
    List<List<Integer>> res = new ArrayList<>();
    List<Integer> list = new ArrayList<>();
    public List<List<Integer>> subsets(int[] nums) {
        process(nums, 0);
        return res;
    }

    public void process(int[] nums, int index) {
        if (index == nums.length) {
            res.add(new ArrayList<>(list));
            return;
        } else {
            list.add(nums[index]);
            process(nums, index + 1);
            list.remove(list.size()-1);
            process(nums, index + 1);
        }
    }


    public List<List<Integer>> subsets1(int[] nums) {
        List<List<Integer>> res = new ArrayList<>();
        List<Integer> list = new ArrayList<>();

        process(nums, 0);
        return res;
    }

    public void process1(int[] nums, int index,List<Integer> list,  List<List<Integer>> res) {
        if (index == nums.length) {
            res.add(new ArrayList<>(list));
        } else {
            process1(nums, index + 1,list,res);
            list.add(nums[index]);
            process1(nums, index + 1,list,res);
            list.remove(list.size()-1);
        }
    }

}
